package com.util;

import javax.imageio.ImageIO;
import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ImageUtil {
    private static final Map<String, Image> imageMap = new HashMap<>();

    static {
        //读图片放集合中
        imageMap.put("bg",getImage("com/res/background.png"));
        imageMap.put("birds",getImage("com/res/birds.png"));
        imageMap.put("land",getImage("com/res/land.png"));
        imageMap.put("pu",getImage("com/res/pie_down.png"));
        imageMap.put("pd",getImage("com/res/pie_up.png"));
        imageMap.put("sb",getImage("com/res/start_button.png"));

    }
    public static Image getImage(String path){
        Image image = null;

        try {
            image =ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }
    public static Image get(String key){
        return imageMap.get(key);
    }
}
